package com.uzai.console.web.profit;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.profit.inviterewardrule.InviteRewardRuleIdDto;
import com.uzai.console.dto.profit.inviterewardrule.InviteRewardRuleInfoDto;
import com.uzai.console.dto.profit.inviterewardrule.InviteRewardRuleQuery;
import com.uzai.console.dto.profit.regrewardrule.RegRewardRuleIdDto;
import com.uzai.console.dto.profit.regrewardrule.RegRewardRuleInfoDto;
import com.uzai.console.dto.profit.regrewardrule.RegRewardRuleQuery;
import com.uzai.console.entity.InviteRewardRule;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.InviteRewardRuleMapper;
import com.uzai.console.service.profit.InviteRewardRuleService;
import com.uzai.console.service.profit.RegRewardRuleService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.profit.inviterewardrule.InviteRewardRuleInfoVo;
import com.uzai.console.vo.profit.regrewardrule.RegRewardRuleInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuqi
 * @date 2021年08月25日 20:15
 */
@Api(value = "奖励方案",tags = "分佣管理|奖励方案")
@ApiSort(4)
@RestController
public class RegRewardRuleContoller extends BaseController {
    private Logger logger = LoggerFactory.getLogger(RegRewardRuleContoller.class);

    @Autowired
    private RegRewardRuleService regRewardRuleService;
    @Autowired
    private InviteRewardRuleService inviteRewardRuleService;
    @Autowired
    private InviteRewardRuleMapper inviteRewardRuleMapper;


    @ApiOperation(value = "分页查询奖励方案列表", notes = "分页查询奖励方案列表", response = RegRewardRuleInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/regRewardRule/findRegRewardRuleList")
    public Object findRegRewardRuleList(@RequestBody RegRewardRuleQuery regRewardRuleQuery){
        return regRewardRuleService.findRegRewardRuleList(regRewardRuleQuery);
    }

    @ApiOperation(value = "查询奖励方案详情", notes = "查询奖励方案详情", response = RegRewardRuleInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/regRewardRule/findRegRewardRuleInfo")
    public Object findRegRewardRuleInfo(@RequestBody RegRewardRuleIdDto regRewardRuleIdDto){
        return regRewardRuleService.findRegRewardRuleInfo(regRewardRuleIdDto);
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加奖励方案", notes = "添加奖励方案")
    @ApiOperationSupport(order = 3)
    @PostMapping("/regRewardRule/addRegRewardRule")
    public Object addRegRewardRule(@RequestBody RegRewardRuleInfoDto regRewardRuleInfoDto){
        regRewardRuleService.addRegRewardRule(regRewardRuleInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改奖励方案", notes = "修改奖励方案")
    @ApiOperationSupport(order = 4)
    @PostMapping("/regRewardRule/updateRegRewardRule")
    public Object updateRegRewardRule(@RequestBody RegRewardRuleInfoDto regRewardRuleInfoDto){
        regRewardRuleService.updateRegRewardRule(regRewardRuleInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除奖励方案", notes = "删除奖励方案")
    @ApiOperationSupport(order = 5)
    @PostMapping("/regRewardRule/deleteRegRewardRule")
    public Object deleteRegRewardRule(@RequestBody RegRewardRuleIdDto regRewardRuleIdDto){
        regRewardRuleService.deleteRegRewardRule(regRewardRuleIdDto);
        return true;
    }

    @ApiOperation(value = "查询邀请奖励下拉框列表", notes = "查询邀请奖励下拉框列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/regRewardRule/findInviteRewardRuleSelect")
    public Object findInviteRewardRuleSelect(){
        List<SelectKeyVo> selectIdVoList = new ArrayList<>();
        InviteRewardRuleQuery inviteRewardRuleQuery =  new InviteRewardRuleQuery();
        inviteRewardRuleQuery.setMerId(getLoginInfo().getMerId());
        List<InviteRewardRule> inviteRewardRuleList = inviteRewardRuleMapper.findByList(inviteRewardRuleQuery);
        if(inviteRewardRuleList != null && inviteRewardRuleList.size() > 0){
            for(InviteRewardRule inviteRewardRule : inviteRewardRuleList){
                SelectKeyVo selectKeyVo =  new SelectKeyVo();
                selectKeyVo.setKey(String.valueOf(inviteRewardRule.getId()));
                //页面显示 身份-类型名称
                selectKeyVo.setValue(inviteRewardRule.getName());
                selectIdVoList.add(selectKeyVo);
            }
        }
        return selectIdVoList;
    }

    @ApiOperation(value = "分页查询邀请奖励列表", notes = "分页查询邀请奖励列表", response = InviteRewardRuleInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/regRewardRule/findInviteRewardRuleList")
    public Object findInviteRewardRuleList(@RequestBody InviteRewardRuleQuery regRewardRuleQuery){
        return inviteRewardRuleService.findInviteRewardRuleList(regRewardRuleQuery);
    }

    @ApiOperation(value = "查询邀请奖励详情", notes = "查询邀请奖励详情", response = InviteRewardRuleInfoVo.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/regRewardRule/findInviteRewardRuleInfo")
    public Object findInviteRewardRuleInfo(@RequestBody InviteRewardRuleIdDto regRewardRuleIdDto){
        return inviteRewardRuleService.findInviteRewardRuleInfo(regRewardRuleIdDto);
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加邀请奖励", notes = "添加邀请奖励")
    @ApiOperationSupport(order = 9)
    @PostMapping("/regRewardRule/addInviteRewardRule")
    public Object addInviteRewardRule(@RequestBody InviteRewardRuleInfoDto regRewardRuleInfoDto){
        inviteRewardRuleService.addInviteRewardRule(regRewardRuleInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改邀请奖励", notes = "修改邀请奖励")
    @ApiOperationSupport(order = 10)
    @PostMapping("/regRewardRule/updateInviteRewardRule")
    public Object updateInviteRewardRule(@RequestBody InviteRewardRuleInfoDto regRewardRuleInfoDto){
        inviteRewardRuleService.updateInviteRewardRule(regRewardRuleInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.RegRewardRule, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除邀请奖励", notes = "删除邀请奖励")
    @ApiOperationSupport(order = 11)
    @PostMapping("/regRewardRule/deleteInviteRewardRule")
    public Object deleteInviteRewardRule(@RequestBody InviteRewardRuleIdDto regRewardRuleIdDto){
        inviteRewardRuleService.deleteInviteRewardRule(regRewardRuleIdDto);
        return true;
    }


}
